package com.yanqu.road.server.gameplayer.module.activity.flowercard;

import com.yanqu.road.entity.activity.flowercards.*;
import com.yanqu.road.entity.activity.flowercards.config.FlowerCardRoundInfo;
import com.yanqu.road.entity.activity.flowercards.config.FlowerCardScoreInfo;
import com.yanqu.road.entity.activity.flowercards.config.FlowerCardSkillInfo;
import com.yanqu.road.entity.activity.flowercards.enums.eFlowerCardState;
import com.yanqu.road.pb.activity.FlowerCardsProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;

import java.util.ArrayList;
import java.util.List;

public class FlowerCardPb {

    public static FlowerCardsProto.FlowerCardsUserDataTemp.Builder getUserDataBuilder(UserFlowerCardsData userData) {
        FlowerCardsProto.FlowerCardsUserDataTemp.Builder userBuilder = FlowerCardsProto.FlowerCardsUserDataTemp.newBuilder();
        userBuilder.setMaxAffinity(userData.getMaxAffinity());
        userBuilder.setTotalAffinity(userData.getTotalAffinity());
        userBuilder.setFreeTimes(userData.getFreeTimes());
        userBuilder.setMaxAppraise(userData.getMaxAppraise());
        userBuilder.setBuySliverToken(userData.getBuySliverToken());
        userBuilder.setBuyGoldToken(userData.getBuyGoldToken());

        for (FlowerCard flowerCard : userData.getCardList()) {
            FlowerCardsProto.FlowerCardsListTemp.Builder cardBuilder = getCardBuilder(flowerCard);
            userBuilder.addCard(cardBuilder);
        }
        GameStatus status = userData.getGameStatus();
        if(status != null) {
            FlowerCardsProto.FlowerCardsGameStatusTemp.Builder statusBuilder = getGameStatusBuilder(status);
            userBuilder.setStatus(statusBuilder);
        }
        return userBuilder;
    }

    public static FlowerCardsProto.FlowerCardsListTemp.Builder getCardBuilder(FlowerCard flowerCard) {
        FlowerCardsProto.FlowerCardsListTemp.Builder cardBuilder = FlowerCardsProto.FlowerCardsListTemp.newBuilder();
        cardBuilder.setCardId(flowerCard.getCardId());
        if(flowerCard.getState() == eFlowerCardState.CLOSE.getValue() && !flowerCard.isPerspective()){
            cardBuilder.setCardId(0);
        }
        if(flowerCard.isShow()){
            cardBuilder.setCardId(flowerCard.getCardId());
        }
        cardBuilder.setPosition(flowerCard.getPosition());
        cardBuilder.setState(flowerCard.getState());
        cardBuilder.setPerspective(flowerCard.isPerspective());
        cardBuilder.setShow(flowerCard.isShow());
        return cardBuilder;
    }

    public static List<FlowerCardsProto.FlowerCardsListTemp> getCardListBuilder(List<FlowerCard> cardList){
        List<FlowerCardsProto.FlowerCardsListTemp> list = new ArrayList<>();
        for (FlowerCard card : cardList) {
            list.add(getCardBuilder(card).build());
        }
        return list;
    }

    public static FlowerCardsProto.FlowerCardsGameStatusTemp.Builder getGameStatusBuilder(GameStatus status) {
        FlowerCardsProto.FlowerCardsGameStatusTemp.Builder statusBuilder = FlowerCardsProto.FlowerCardsGameStatusTemp.newBuilder();
        statusBuilder.setRound(status.getRound());
        statusBuilder.setEfface(status.getEfface());
        statusBuilder.setCombo(status.getCombo());
        statusBuilder.setFlowerDew(status.getFlowerDew());
        statusBuilder.addAllCardOrder(status.getCardOrder());
        statusBuilder.setSettle(status.isSettle());
        statusBuilder.setRowNum(status.getRowNum());
        statusBuilder.setColNum(status.getColNum());
        statusBuilder.setTotalStep(status.getTotalStep());
        statusBuilder.setAffinity(status.getAffinity());
        statusBuilder.setSkillSelectTimes(status.getSelectTimes());
        for (int id : status.getSkillSelectList()) {
            FlowerCardsProto.FlowerCardsSkillTemp.Builder skillBuilder = FlowerCardsProto.FlowerCardsSkillTemp.newBuilder();
            skillBuilder.setLv(1);
            skillBuilder.setType(id);
            statusBuilder.addSelectSkill(skillBuilder);
        }

        //技能
        for (FlowerCardFlowerSkill flowerSkill : status.getSkillList()) {
            FlowerCardsProto.FlowerCardsSkillTemp.Builder skillBuilder = FlowerCardsProto.FlowerCardsSkillTemp.newBuilder();
            skillBuilder.setType(flowerSkill.getType());
            skillBuilder.setLv(flowerSkill.getLv());
            statusBuilder.addSkill(skillBuilder);
        }

        //美人
        for (FlowerCardBeautyNpc beautyNpc : status.getBeautyNpcList()) {
            FlowerCardsProto.FlowerCardsBeautyNpcTemp.Builder beautyBuilder = FlowerCardsProto.FlowerCardsBeautyNpcTemp.newBuilder();
            beautyBuilder.setBeautyId(beautyNpc.getBeautyId());
            beautyBuilder.setFlowerDew(beautyNpc.getFlowerDew());
            beautyBuilder.setPatience(beautyNpc.getPatience());
            beautyBuilder.setInitPatience(beautyNpc.getInitPatience());
            statusBuilder.addNpc(beautyBuilder);
        }
        return statusBuilder;
    }

    public static FlowerCardsProto.FlowerCardsRoundConfigTemp.Builder getMissionBuilder(FlowerCardRoundInfo roundInfo) {
        FlowerCardsProto.FlowerCardsRoundConfigTemp.Builder builder = FlowerCardsProto.FlowerCardsRoundConfigTemp.newBuilder();
        builder.setRounds(roundInfo.getRounds());
        builder.setStepNum(roundInfo.getStepNum());
        builder.addAllUnlockSkills(roundInfo.getUnlockSkills());
        builder.addAllBeautyNum(roundInfo.getBeautyNum());
        builder.addAllNpcWeights(roundInfo.getNpcWeights());
        builder.addAllNpcSufferance(roundInfo.getNpcSufferance());
        builder.addAllNpcReward(roundInfo.getNpcReward());
        builder.addAllBeautyList(roundInfo.getBeautyList());
        builder.setType(roundInfo.getType());
        builder.setNpcNum(roundInfo.getNpcNum());
        return builder;
    }

    public static FlowerCardsProto.FlowerCardsScoreConfigTemp.Builder getScoreBuilder(FlowerCardScoreInfo scoreInfo, String language) {
        FlowerCardsProto.FlowerCardsScoreConfigTemp.Builder builder = FlowerCardsProto.FlowerCardsScoreConfigTemp.newBuilder();
        builder.setId(scoreInfo.getId());
        builder.setIcon(scoreInfo.getIcon());
        builder.setName(ServerLanguageMgr.getContent(scoreInfo.getName(), language));
        builder.setScore(scoreInfo.getScore());
        builder.setRewards(scoreInfo.getRewards());
        return builder;
    }

    public static FlowerCardsProto.FlowerCardsSkillConfigTemp.Builder getSkillBuilder(FlowerCardSkillInfo skillInfo, String language) {
        FlowerCardsProto.FlowerCardsSkillConfigTemp.Builder builder = FlowerCardsProto.FlowerCardsSkillConfigTemp.newBuilder();
        builder.setSkillId(skillInfo.getSkillId());
        builder.setSkillLevel(skillInfo.getSkillLevel());
        builder.setSkillParam(skillInfo.getSkillParam());
        builder.setIcon(skillInfo.getIcon());
        builder.setSkillIntro(ServerLanguageMgr.getContent(skillInfo.getSkillIntro(), language));
        builder.setSkillName(ServerLanguageMgr.getContent(skillInfo.getSkillName(), language));
        builder.setSkillDesc(ServerLanguageMgr.getContent(skillInfo.getSkillDesc(), language));
        return builder;
    }

    public static FlowerCardsProto.FlowerCardsSkillTemp.Builder getFlowerCardsSkillTemp(int skill, int lv){
        FlowerCardsProto.FlowerCardsSkillTemp.Builder builder = FlowerCardsProto.FlowerCardsSkillTemp.newBuilder();
        builder.setType(skill);
        builder.setLv(lv);
        return builder;
    }
}
